<?php

class FormScrollBar extends FormControl {
	
	public static $property = array(
		'wbtype',
		'name',
		'caption',
		'x',
		'y',
		'width',
		'height',
		'disabled',
		'tranparent',
		'autorepeat',
		'visible'
	);		
	
	public function __construct() { 
		parent::__construct(array(
			'wbtype' => 'ScrollBar',
			'x' => 0,
			'y' => 0,
			'width' => 20,
			'height' => 100
		));
	}

	/**
	 * 컨트롤 그리기 
	 * 
	 * @param WBGraphics $graphics
	 */
	public function displayControl(WBGraphics $g) {

		$xstart = $this->getOption('x');
		$ystart = $this->getOption('y');
		$width = $this->getOption('width');
		$height = $this->getOption('height');		

		
		$g->rect($xstart, $ystart, $width, $height, FormControl::DISABLED, true);
		
		if($height < $width) {
			$this->displayHorizon($g, " ", $xstart, $ystart, $width, $height);
			return;
		}

		$btnHeight = min(18, $height/2);
		
		$this->displayButton($g, " ", $xstart, $ystart, $width, $btnHeight);
		$this->displayButton($g, " ", $xstart, $ystart + $btnHeight, $width, min(24, $height - ($btnHeight * 2)));
		$this->displayButton($g, " ", $xstart, $ystart + $height - $btnHeight, $width, $btnHeight);
		
		if ($width > 7 && $height > 11) { 
			$image1 = WBImage::loadFile(RESOURCE_HOME . "symb_uparrow.bmp"); 
			$image2 = WBImage::loadFile(RESOURCE_HOME . "symb_dnarrow.bmp"); 
						
			$g->image($image1->instance, $xstart + ($width - 7)/2, $ystart + $btnHeight/2 - 3 , 7, 4, GREEN);
			$g->image($image2->instance, $xstart + ($width - 7)/2, $ystart + $height - $btnHeight + $btnHeight/2 - 2 , 7, 4, GREEN);

			$image1->destroy();
			$image2->destroy();

		}		

	}
	
	public function displayHorizon($g, $caption, $xstart, $ystart, $width, $height) { 
		// Draw buttons
		$btnwidth = min(18, $width / 2);
	
		$this->displayButton($g, " ", $xstart, $ystart, $btnwidth, $height);
		$this->displayButton($g, " ", $xstart + $btnwidth, $ystart, min(24, $width - ($btnwidth * 2)), $height);
		$this->displayButton($g, " ", $xstart + $width - $btnwidth, $ystart, $btnwidth, $height);
	
		// Draw arrows
		if($height > 7 && $width > 11 ) {
			
			$image1 = WBImage::loadFile(RESOURCE_HOME . "symb_lfarrow.bmp"); 
			$image2 = WBImage::loadFile(RESOURCE_HOME . "symb_rtarrow.bmp"); 
			
			$g->image($image1->instance, $xstart + $btnwidth / 2 - 3, $ystart + ($height - 7) / 2, 4, 7, GREEN);
			$g->image($image2->instance, $xstart + $width - $btnwidth + $btnwidth / 2 - 3, $ystart + ($height - 7) / 2, 4, 7, GREEN);

			$image1->destroy();
			$image2->destroy();
						
		}
	}
	
	public function getProperty() { 
		return self::$property;
	}
}


?>